import {reqgetDetailInfo, reqAddshopCart} from "@/api";
import {uuidToken} from "@/utils/uuid_token";

const state = {
    detailInfo: {},
    uuid_token: uuidToken(),
}

const mutations = {
    GetDetailInfo(state, detailInfo){
        state.detailInfo = detailInfo;
    },
}

const actions = {
    async getDetailInfo({commit}, skuId){
        let result = await reqgetDetailInfo(skuId);
        console.log("detailInfo", result)
        if(result.code == 200){
            commit("GetDetailInfo", result.data) 
        }
    },
    async addShopCart({commit}, {skuId, skuNum}){
        let result = await reqAddshopCart(skuId, skuNum);
    },
}

const getters = {
    categoryView(state){
        return state.detailInfo.categoryView || {};
    },
    skuInfo(state){
        return state.detailInfo.skuInfo || {};
    },
    spuSaleAttrList(state){
        return state.detailInfo.spuSaleAttrList || [];
    },
}

export default {
    state,
    mutations,
    actions,
    getters
}